package com.ruoyi.project.yingyu.transferorder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.yingyu.transferorder.domain.TransferOrder;
import com.ruoyi.project.yingyu.transferorder.service.ITransferOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 转帐订单Controller
 * 
 * @author shixiangwen
 * @date 2020-02-17
 */
@Controller
@RequestMapping("/yingyu/transferorder")
public class TransferOrderController extends BaseController
{
    private String prefix = "yingyu/transferorder";

    @Autowired
    private ITransferOrderService transferOrderService;

    @RequiresPermissions("yingyu:transferorder:view")
    @GetMapping()
    public String transferorder()
    {
        return prefix + "/transferorder";
    }

    /**
     * 查询转帐订单列表
     */
    @RequiresPermissions("yingyu:transferorder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransferOrder transferOrder)
    {
        startPage();
        List<TransferOrder> list = transferOrderService.selectTransferOrderList(transferOrder);
        return getDataTable(list);
    }

    /**
     * 导出转帐订单列表
     */
    @RequiresPermissions("yingyu:transferorder:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransferOrder transferOrder)
    {
        List<TransferOrder> list = transferOrderService.selectTransferOrderList(transferOrder);
        ExcelUtil<TransferOrder> util = new ExcelUtil<TransferOrder>(TransferOrder.class);
        return util.exportExcel(list, "transferorder");
    }

    /**
     * 新增转帐订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存转帐订单
     */
    @RequiresPermissions("yingyu:transferorder:add")
    @Log(title = "转帐订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransferOrder transferOrder)
    {
        return toAjax(transferOrderService.insertTransferOrder(transferOrder));
    }

    /**
     * 修改转帐订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TransferOrder transferOrder = transferOrderService.selectTransferOrderById(id);
        mmap.put("transferOrder", transferOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存转帐订单
     */
    @RequiresPermissions("yingyu:transferorder:edit")
    @Log(title = "转帐订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransferOrder transferOrder)
    {
        return toAjax(transferOrderService.updateTransferOrder(transferOrder));
    }

    /**
     * 删除转帐订单
     */
    @RequiresPermissions("yingyu:transferorder:remove")
    @Log(title = "转帐订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transferOrderService.deleteTransferOrderByIds(ids));
    }
}
